/**
 * 
 */
function loadAllCategory() {
	$.get("getAllCategory",function(data){
		$.each(data,function(key,value) {
			$(".nav_list").append("<a href=\"#\"><div class=\"category\">" + value.categoryName + "</div></a>");
		});
	},'json');
}

function loadAllCategoryForCombobox() {
	$.get("getAllCategory",function(data){
		$.each(data,function(key,value) {
			var optionTag = '<option value="' + value.categoryId + '">' + value.categoryName +'</option>';
			$("#categories").append(optionTag);
		});
	},'json');
}

function loadBookDetail(bookId) {
	$.get("getBookDetailServlet",{bookId: bookId},function(data){
		$(".book_title").append(data.bookTitle);
		$(".book_author").append(data.bookAuthor);
		$(".book_price").append('$' + data.bookPrice);
		$(".book_desc").append(data.bookDesc);
	},'json');
}

function loadAllBook() {
	$.get("getAllBook",function(data){
		$.each(data,function(key,value) {
			var img = '<img class="book_cover" src="http://www.nortownpress.com/images/JavaCvr.jpg" width="110px" height="150px"/>';
			var title = '<br/><span class="book_info book_title">' + value.bookTitle + '</span><div class="separator" style="margin: 0 20px 0 20px"></div>';
			var author = '<span class="book_info book_author">' + value.bookAuthor + '</span>';
			var price = '<br/><span class="book_info book_price">$' + value.bookPrice + '</span>';
			var btDetail = '<br/><div class="frame_button"><a href="http://localhost:8080/BookStore/getBookDetail?bookId=' + value.bookId + '"><button class="detail">Detail</button></a>';
			var btBuy = '<button>Buy</button></div>';
			$("#book_content").append("<div class=\"book\">" + img + title + author + price + btDetail + btBuy + "</div>");
		});
	},'json');
}

$(document).ready(function () {
	loadAllCategory();
});